<template>
  <div class="container">
    <div class="header">教师管理模块 >> 教师信息管理</div>
    <div class="list-container">
      <div class="list-search">
        教师姓名:
        <el-input
          class="input"
          v-model="teacherRef.nickName"
          placeholder="教师姓名"
        ></el-input>
        所属专业：
        <el-select v-model="teacherRef.major" placeholder="请选择教师所属专业">
          <el-option
            v-for="(item, index) in majorOptions"
            :key="index"
            :value="item"
          ></el-option>
        </el-select>
        教师职称：
        <el-select v-model="teacherRef.profession" placeholder="请选择教师职称">
          <el-option
            v-for="(item, index) in professionOptions"
            :key="index"
            :value="item"
          ></el-option>
        </el-select>
        <el-button
          @click="search"
          class="search-btn"
          type="primary"
          icon="el-icon-search"
        >
          搜索
        </el-button>
      </div>
      <div>
        <el-table :data="teacherList" style="width: 100%" v-loading="loading">
          <el-table-column
            prop="nickName"
            label="姓名"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="major"
            label="专业"
            width="200"
          ></el-table-column>
          <el-table-column
            prop="profession"
            label="职称"
            width="180"
          ></el-table-column>
          <el-table-column
            prop="createTime"
            label="创建日期"
            width="200"
          ></el-table-column>
          <el-table-column
            prop="updateTime"
            label="修改日期"
            width="200"
          ></el-table-column>
          <el-table-column label="操作" width="180">
            <template #default="scope">
              <router-link
                class="operation"
                :to="{ path: '/admin/teachers/' + scope.row.id }"
              >
                <i class="el-icon-edit-outline"></i>
                更多操作
              </router-link>
            </template>
            <!-- <template>
              <router-link
                :to="{ path: '/admin/teachers/' + id }"
              ></router-link>
            </template> -->
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { User } from "@/datasource/Type";
import { State } from "@/store";
import { useStore } from "vuex";
import { computed, defineComponent, ref } from "vue";
import { LIST_TEACHERS } from "@/store/VuexTypes";

export default defineComponent({
  setup() {
    const store = useStore<State>();
    const loading = computed(() => store.state.loading);
    const teacherList = computed(() => store.state.teacherList);
    const teacher: User = {
      nickName: null,
      profession: null,
      major: null,
    };
    const teacherRef = ref<User>(teacher);
    const majorOptions = ref([
      "",
      "计算机科学与技术",
      "软件工程",
      "信息管理与信息系统",
    ]);
    const professionOptions = ref(["", "教授", "副教授", "讲师"]);
    store.dispatch(LIST_TEACHERS, {
      nickName: teacherRef.value.nickName,
      profession: teacherRef.value.profession,
      major: teacherRef.value.major,
    });
    const search = () => {
      let nickName = null;
      let major = null;
      let profession = null;
      if (
        teacherRef.value.nickName == null ||
        teacherRef.value.nickName.trim().length == 0
      ) {
        nickName = null;
      } else {
        nickName = teacherRef.value.nickName;
      }
      if (
        teacherRef.value.major == null ||
        teacherRef.value.major.length == 0
      ) {
        major = null;
      } else {
        major = teacherRef.value.major;
      }
      if (
        teacherRef.value.profession == null ||
        teacherRef.value.profession.length == 0
      ) {
        profession = null;
      } else {
        profession = teacherRef.value.profession;
      }
      store.dispatch(LIST_TEACHERS, {
        nickName: nickName,
        profession: profession,
        major: major,
      });
    };
    return {
      teacherRef,
      professionOptions,
      majorOptions,
      loading,
      search,
      teacherList,
    };
  },
});
</script>

<style scoped>
.container {
  height: 100%;
  width: 100%;
}
.header {
  width: 90%;
  padding: 5px 5px 10px;
  border-bottom: 1px solid #ccc;
  font-size: 12px;
  color: grey;
  margin-bottom: 20px;
}
.list-container {
  height: 92%;
  width: 100%;
}
.list-search {
  border: 1px solid #ccc;
  width: 90%;

  margin: 10px auto;
  border-radius: 5px;
  padding: 15px 0 15px 30px;
  box-shadow: 5px 5px 5px #ccc;
}
.input {
  width: 150px;
}
.search-btn {
  margin-left: 50px;
}
.operation {
  text-decoration: none;
  display: block;
  width: 100px;

  border-radius: 5px;

  color: white;
  background-color: violet;
  text-align: center;
  padding: 5px;
}
</style>
